package com.example.app.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.app.R;
import com.example.app.viewmodel.home.Channel;

import java.util.List;

public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ViewHolder> {
    private Context ctx;
    private List<Channel> channels;

    public ChannelAdapter(Context ctx, List<Channel> channels) {
        this.ctx = ctx;
        this.channels = channels;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(this.ctx).inflate(R.layout.adapter_home_channel,null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(this.ctx)
                .load(channels.get(position).getIconUrl())
                .into(holder.home_channel_img);
        holder.home_channel_txt.setText(channels.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return channels.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView home_channel_img;
        TextView home_channel_txt;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            home_channel_img = itemView.findViewById(R.id.home_channel_img);
            home_channel_txt = itemView.findViewById(R.id.home_channel_txt);
        }
    }
}
